<div class="open-form">
    <div class="open-model">
        <div class="open-auto">
            <button class="layui-btn" id="isCheckFun" style="border-radius: 4px;margin-bottom: 10px">确认选择</button>
            <table  class="layui-table" id="deliveryPlanFormTableTable"
                   lay-filter="deliveryPlanFormTableTable"></table>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">关闭</button>
        </div>
    </div>
</div>
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'upload', 'tree', 'laytpl'], async function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laytpl = layui.laytpl;
        const nowData = {...parentData}
        const id = nowData.id
        table.render({
            elem: '#deliveryPlanFormTableTable',
            // url: config.base + `enterprise/sell/admin/customerProductCatalog/list?limit=9999&customerId=${id}`,
            // where: {purchaseDeliveryRecordId: id},
            page: false,
            cellMinWidth: 100,
            cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {type: 'numbers', title: '序号'}
                , {field: 'cusProductId', align: 'center', title: 'ID',}
                , {field: 'customerSkuName', align: 'center', title: '产品名称',}
                , {field: 'customerSpecCode', align: 'center', title: '规格码',}
                , {field: 'proTypeName', align: 'center', title: '产品类型'}
                ,{field: 'offerMoney', align: 'center', title: '产品单价',width:100}
                , {field: 'weight', align: 'center', title: '重量',}
                , {field: 'updateTime', align: 'center', title: '发布时间'}
                , {field: 'createTime', align: 'center', title: '上架时间'}
            ]],
            done: function () {
                if (nowData.cacheList.length > 0) {
                    table.cache['deliveryPlanFormTableTable'].forEach((item, index) => {
                        const isSelected = nowData.cacheList.some(checkItem => checkItem.cusProductId === item.cusProductId);
                        if (isSelected) {
                            item["LAY_CHECKED"] = true
                            $('div.layui-table-body input[name="layTableCheckbox"]:eq(' + (index) + ')').prop('checked', true);
                            $('div.layui-table-body input[name="layTableCheckbox"]:eq(' + (index) + ')').next().addClass('layui-form-checked');
                        }
                    });
                }
                form.render('checkbox');
            }
        });
        if (id) {
            const res = await admin.reqPro(`enterprise/sell/admin/order/detail/` + id, {})
            let list=res.data.orderProList.map(v=>{
                delete v.id
                return v
            })
            table.reload('deliveryPlanFormTableTable',{data:list})
            $('#isCheckFun').click(() => {
                var checkStatus = table.checkStatus('deliveryPlanFormTableTable'); // 'demo'是表格的ID
                var data = checkStatus.data;  // 选中的数据
                console.log('data',data)
                if (typeof parent.layui !== 'undefined') {
                    childData.list = data.map(v => {
                        return v
                    })
                    layer.close(nowData.zindex); // 关闭指定的弹窗
                }
            })
        }

    })
</script>